﻿''' <summary>
''' This class is used to capture a number of Process attributes in a single "structure" (since the use of a Class is preferred over a Structure).
''' </summary>
''' <remarks>
''' The name EnumeratedProcess has been chosen as a way to distinguish from the default Process object in the Framework, and is meant to be more generic (and thus more accurately descriptive) than the other choices considered including UserProcess, VisibleProcess or DisplayedProcess.
''' </remarks>
Public Class EnumeratedProcess

#Region " Properties "

    ''' <summary>
    ''' Tracks whether the process is still running i.e. if it (a) was detected during initialization, and (b) subsequently exited.
    ''' </summary>
    ''' <remarks>
    ''' Used to enable CacheMyWork to track all HiddenApps, whether they're detected on the system or not.  It is also useful to track any changes of state between startup of CacheMyWork and when one of the lists is displayed to the user.
    ''' </remarks>
    Private _Exists As Boolean
    Public Property Exists() As Boolean
        Get
            Return _Exists
        End Get
        Set(ByVal value As Boolean)
            _Exists = value

            ' When the process is determined to no longer be running, set _ProcessWillBeDisplayedToUser = False so it won't be among the possible choices.
            If value = False Then
                _ProcessWillBeDisplayedToUser = False
            End If
        End Set
    End Property

    ''' <summary>
    ''' Indicates whether the process has any windows (visible or not).
    ''' </summary>
    ''' <remarks>
    ''' This is an abstraction of the test that checks whether the Process.MainWindowHandle = 0.  
    ''' Processes whose MainWindowHandle property is non-zero have at least one window.
    ''' </remarks>
    Private _HasWindow As Boolean
    Public Property HasWindow() As Boolean
        Get
            Return _HasWindow
        End Get
        Set(ByVal value As Boolean)
            _HasWindow = value

            ' When the process is determined to have no Window, set _ProcessWillBeDisplayedToUser = False so it won't be among the possible choices.
            If value = False Then
                _ProcessWillBeDisplayedToUser = False
            End If
        End Set
    End Property

    ''' <summary>
    ''' Indicates whether the process has been "hidden" by the user during the current application session.
    ''' </summary>
    ''' <remarks>
    ''' This will assist the developer in distinguishing between apps hidden via user settings (read in during startup) and apps hidden by use of the Hide Applications dialog.
    ''' </remarks>
    Private _IsHiddenByUser As Boolean
    Public Property IsHiddenByUser() As Boolean
        Get
            Return _IsHiddenByUser
        End Get
        Set(ByVal value As Boolean)
            _IsHiddenByUser = value

            ' When the process is hidden by the user, set _ProcessWillBeDisplayedToUser = False so it won't be among the possible choices.
            If value = True Then
                _ProcessWillBeDisplayedToUser = False
            End If
        End Set
    End Property

    ''' <summary>
    ''' Indicates whether the process has been removed from the ProcessesToShowUser collection by virtue of having been read in from user settings.
    ''' </summary>
    ''' <remarks></remarks>
    Private _IsRemovedProgrammatically As Boolean
    Public Property IsRemovedProgrammatically() As Boolean
        Get
            Return _IsRemovedProgrammatically
        End Get
        Set(ByVal value As Boolean)
            _IsRemovedProgrammatically = value

            ' When the process has been removed, set _ProcessWillBeDisplayedToUser = False so it won't be among the possible choices.
            If value = True Then
                _ProcessWillBeDisplayedToUser = False
            End If
        End Set
    End Property

    ' TODO: this property may turn out to be redundant once _ProcessWillBeDisplayedToUser has been fully implemented.
    ''' <summary>
    ''' Summarizes the result of all properties that could be used to "filter out" the processes that aren't of interest to the end user, and shouldn't be presented as a member of the list of cacheable processes" That is, those processes that would be of little or no value to cache for launch at next logon.
    ''' </summary>
    ''' <value></value>
    ''' <returns></returns>
    ''' <remarks>This will capture the state of such other properties of this object as IsHiddenByUser and IsRemovedProgrammatically.</remarks>
    Private ReadOnly Property _IsProcessVisible() As Boolean
        Get
            If _IsRemovedProgrammatically = True Or _IsHiddenByUser = True Then
                Return True
            Else
                Return False
            End If
        End Get
    End Property
    Public ReadOnly Property IsProcessVisible() As Boolean
        Get
            Return _IsProcessVisible
        End Get
    End Property

    ''' <summary>
    ''' Exposes the result of the P/invoke query to determine if the Process' window is visible.
    ''' </summary>
    ''' <remarks>
    ''' This will obviously only be true if the HasWindow property returns True.</remarks>
    Private _IsWindowVisible As Boolean
    Public Property IsWindowVisible() As Boolean
        Get
            Return _IsWindowVisible
        End Get
        Set(ByVal value As Boolean)
            _IsWindowVisible = value

            ' When the process is determined to have no visible Window, set _ProcessWillBeDisplayedToUser = False so it won't be among the possible choices.
            ' TODO: Re-enable this if we can figure out a better way to determine if the Window is truly visible (not just the Win32 IsWindowVisible property that doesn't work well.
            'If value = False Then
            '    _ProcessWillBeDisplayedToUser = False
            'End If
        End Set
    End Property


    Private _ProcessCommandLine As String
    Public Property ProcessCommandLine() As String
        Get
            Return _ProcessCommandLine
        End Get
        Set(ByVal value As String)
            _ProcessCommandLine = value
        End Set
    End Property


    Private _ProcessDescriptiveName As String
    Public Property ProcessDescriptiveName() As String
        Get
            Return _ProcessDescriptiveName
        End Get
        Set(ByVal value As String)
            _ProcessDescriptiveName = value
        End Set
    End Property


    Private _ProcessName As String
    Public Property ProcessName() As String
        Get
            Return _ProcessName
        End Get
        Set(ByVal value As String)
            _ProcessName = value
        End Set
    End Property


    ''' <summary>
    ''' Represents the Username for the Process object.
    ''' </summary>
    ''' <remarks>Allows CacheMyWork to determine whether the user context in which the Process was launched is the same as the user currently running CacheMyWork.</remarks>
    Private _ProcessOwner As String
    Public Property ProcessOwner() As String
        Get
            Return _ProcessOwner
        End Get
        Set(ByVal value As String)
            _ProcessOwner = value
        End Set
    End Property

    ''' <summary>
    ''' Represents the state that is set to True when process is first enumerated, and then is set to False as processes are eliminated by the Business Logic layer.
    ''' </summary>
    ''' <remarks></remarks>
    Private _ProcessWillBeDisplayedToUser As Boolean
    Public Property ProcessWillBeDisplayedToUser() As Boolean
        Get
            Return _ProcessWillBeDisplayedToUser
        End Get
        Set(ByVal value As Boolean)
            _ProcessWillBeDisplayedToUser = value
        End Set
    End Property

#End Region

End Class
